﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.RunProperties
{
    /// <summary>
    /// Text expansion/compression value. Min: 0, Max: 600
    /// </summary>
    [XmlRoot("spacing", Namespace = Constants.WordMain)]
    public class TextExpansion : XmlSerializable, IRunPropElement
    {
        [XmlIgnore]
        private int scale;

        [Optional]
        [XmlAttribute("w", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<int> Scale 
        {
            get { return scale; }
            set { scale = Math.Max(0, Math.Min(value.Value, 600)); }
        }

        public TextExpansion() { }

        public void Copy(object obj)
        {
            if (obj is TextExpansion)
            {
                this.Scale = (obj as TextExpansion).Scale;
            }
        }
    }
}
